<template>
<div>
  <!-- 一条文章单元格 -->
  <van-cell>
    <!-- 标题区域的插槽 -->
    <template #title>
      <div class="title-box">
        <!-- 标题 -->
        <span>{{artObj.title}}</span>
        <van-image v-if="artObj.cover.type===1" class="thumb" :src='artObj.cover.images[0]'>
           <template v-slot:error>加载失败</template>
        </van-image>
      </div>
      <div class="thumb-box"  v-if="artObj.cover.type>1">
      <van-image v-for="imgUrl,index in artObj.cover.images" :key="index"
      :src="artObj.cover.images[index]"
      alt="" class="thumb">
       <template v-slot:error>加载失败</template>
       </van-image>
    </div>
    </template>
    <!-- label 区域的插槽 -->

    <template #label>
      <div class="label-box">
        <div>
          <span>{{artObj.aut_name}}</span>
          <span>{{artObj.count}}评论</span>
          <span>{{timeAgo(artObj.pubdate)}}</span>
        </div>
        <!-- 反馈按钮 -->
        <van-icon name="cross" @click.stop="show = true"  v-show="isShow"/>
      </div>
    </template>
  </van-cell>
  <!-- 反馈 -->
  <van-action-sheet v-model="show" :actions="actions" @select="onSelect"   :cancel-text="bottomText"
  @cancel="onCancel" @close ="closeFn" @click.stop="" />

</div>
</template>

<script>
import { timeAgo } from '@/utils/date.js'
import { firstActions, secondActions } from '@/utils/request.js'
// import { Toast } from 'vant'
export default {
  data () {
    return {
      show: false,
      actions: firstActions,
      bottomText: '取消'
    }
  },
  props: {
    artObj: Object,
    isShow: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    timeAgo,
    onSelect (action, item) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
      // this.show = false
      // Toast(item.name)
      if (action.name === '反馈垃圾内容') {
        this.actions = secondActions
        this.bottomText = '返回'
      } else if (action.name === '不感兴趣') {
        this.$emit('dislike', this.artObj.art_id)
        this.show = false
      } else {
        this.$emit('reportEV', this.artObj.art_id, action.value)
      }
      console.log(item)
    },
    onCancel () {
      if (this.bottomText === '返回') {
        this.show = true
        this.actions = firstActions
        this.bottomText = '取消'
      }
    },
    closeFn () {
      this.actions = firstActions
      this.bottomText = '取消'
    }
  }

}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span{
    margin: 0 3px;
    &:first-child{
        margin-left: 0;
    }
}
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
